#pragma once
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "Log.hpp"

using namespace LogModule;

class InetAddr
{
public:
    InetAddr(const struct sockaddr_in& addr)
        : _addr(addr)
    {
        _ip = inet_ntoa(_addr.sin_addr);
        _port = ntohs(_addr.sin_port);
    }

    bool operator==(const InetAddr& addr)
    {
        return (_ip == addr._ip && _port == addr._port);
    }
    std::string Ip() const {return _ip;}
    in_port_t Port() const {return _port;}
    struct sockaddr_in NetAddr() const {return _addr;}
private:
    std::string _ip;
    in_port_t _port;
    struct sockaddr_in _addr;
};